Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@types/pdfjs-dist
Advanced tools
Stub TypeScript definitions entry for pdfjs-dist, which provides its own types definitions
@types/pdfjs-dist provides TypeScript definitions for the pdfjs-dist library, which is a popular library for working with PDF files in JavaScript. It allows developers to render PDF documents in web applications, extract text, and interact with PDF content programmatically.
Rendering PDF Pages
This feature allows you to render a PDF page onto an HTML canvas element. The code sample demonstrates how to load a PDF document, get the first page, and render it on a canvas.
const pdfjsLib = require('pdfjs-dist');
const canvas = document.getElementById('pdf-canvas');
const context = canvas.getContext('2d');
pdfjsLib.getDocument('path/to/document.pdf').promise.then(function(pdf) {
pdf.getPage(1).then(function(page) {
const viewport = page.getViewport({ scale: 1.5 });
canvas.height = viewport.height;
canvas.width = viewport.width;
const renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
});
});
Extracting Text from PDF
This feature allows you to extract text content from a PDF page. The code sample demonstrates how to load a PDF document, get the first page, and extract its text content.
const pdfjsLib = require('pdfjs-dist');
pdfjsLib.getDocument('path/to/document.pdf').promise.then(function(pdf) {
pdf.getPage(1).then(function(page) {
page.getTextContent().then(function(textContent) {
const textItems = textContent.items;
let finalString = '';
for (let i = 0; i < textItems.length; i++) {
finalString += textItems[i].str + ' ';
}
console.log(finalString);
});
});
});
Navigating PDF Pages
This feature allows you to navigate through the pages of a PDF document. The code sample demonstrates how to load a PDF document, render a specific page, and navigate to the next or previous page.
const pdfjsLib = require('pdfjs-dist');
let pdfDoc = null;
let currentPage = 1;
pdfjsLib.getDocument('path/to/document.pdf').promise.then(function(pdf) {
pdfDoc = pdf;
renderPage(currentPage);
});
function renderPage(pageNum) {
pdfDoc.getPage(pageNum).then(function(page) {
const viewport = page.getViewport({ scale: 1.5 });
const canvas = document.getElementById('pdf-canvas');
const context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
const renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
});
}
function goToNextPage() {
if (currentPage < pdfDoc.numPages) {
currentPage++;
renderPage(currentPage);
}
}
function goToPreviousPage() {
if (currentPage > 1) {
currentPage--;
renderPage(currentPage);
}
}
pdf-lib is a library for creating and modifying PDF documents in JavaScript. Unlike pdfjs-dist, which focuses on rendering and extracting content from existing PDFs, pdf-lib allows you to create new PDFs and modify existing ones programmatically.
pdf2json is a library that converts PDF files to JSON format. It is useful for extracting structured data from PDFs, whereas pdfjs-dist is more focused on rendering and interacting with PDF content in a web application.
pdfkit is a library for generating PDF documents in Node.js. It allows you to create complex PDF documents with text, images, and graphics. While pdfjs-dist is used for rendering and extracting content from PDFs, pdfkit is used for creating new PDF documents.
This is a stub types definition for @types/pdfjs-dist (http://mozilla.github.io/pdf.js/).
pdfjs-dist provides its own type definitions, so you don't need @types/pdfjs-dist installed!
FAQs
Stub TypeScript definitions entry for pdfjs-dist, which provides its own types definitions
The npm package @types/pdfjs-dist receives a total of 107,759 weekly downloads. As such, @types/pdfjs-dist popularity was classified as popular.
We found that @types/pdfjs-dist demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.